import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutterdemo/0demo/provider/02my_demo/provider_data/common_data.dart';
import 'package:provider/provider.dart';

// 无状态的
class TabViewWidget6 extends StatelessWidget {
  final UserModel userModel;

  const TabViewWidget6({Key key, this.userModel}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    print("page 6 build");
    return Container(
      padding: EdgeInsets.all(20.w),
      child: Card(
        child: Column(
          children: <Widget>[
            Text(_getLatestUserInfo()),
            FlatButton(
              onPressed: () {
                _changeUserModel(context);
              },
              child: Text("修改UserModel"),
            )
          ],
        ),
      ),
    );
  }

  String _getLatestUserInfo() {
    return userModel == null ? "null" : userModel.toString();
  }

  void _changeUserModel(BuildContext context) {
    context.read<CommonData>().changeUserModel();
  }
}
